<!DOCTYPE html>
<html>
<head>
    <title>用户积分</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="木兰湾管理系统">
    <script type="text/javascript" src="../../static/include/header-css.js"></script>
</head>
<body>
<div class="weui-form-preview">
    <div class="weui-form-preview__hd">
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">统计日期</label>
            <em class="weui-form-preview__value"><label id="statDate"></label></em>
        </div>
    </div>
    <div class="weui-form-preview__bd">
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">得分次数</label>
            <span class="weui-form-preview__value"><label id="totalCount"></label></span>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">当日积分</label>
            <span class="weui-form-preview__value"><label id="totalPoints"></label></span>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">累计积分</label>
            <span class="weui-form-preview__value"><label id="currentPoints"></label></span>
        </div>
    </div>
    <div class="weui-form-preview__ft">
        <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:doDailyRewardPointsStat(-1)">前一天</a>
        <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:doDailyRewardPointsStat(1)">后一天</a>
        <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="userRewardPointsStat.html">统计图</a>
    </div>
</div>
<!--列表数据显示-->
<div id="dataContent"></div>
<!--滚动加载-->
<div class="weui-loadmore" id="loadingSpan">
    <span class="weui-loadmore__tips"></span>
</div>
<div class="button_sp_area" align="center">
    <a href="javascript:scroll(0,0);" class="weui-btn weui-btn_mini weui-btn_primary">返回顶部</a>
</div>
<form id="search-form">
    <input type="hidden" name='page' value="1" id="page"/>
    <input type="hidden" name='startDate'/>
    <input type="hidden" name='endDate'/>
</form>
<br>
<script type="text/javascript" src="../../static/include/footer-js.js"></script>
<script>
    var currentDays=0;
    $(function() {
        pushRefresh(loadUserRewardPoints);
        doDailyRewardPointsStat(currentDays);
    });
    function doDailyRewardPointsStat(n) {
        currentDays=currentDays+n;
        var date = getDay(currentDays);
        var url='/userRewardPointRecord/dailyStat?date='+date;
        doAjax(null,url,'GET',false,function(data) {
            //setElementInnerHTML('dataContent','');
            if(undefined==data){
                $.toptip('无更多数据', 'error');
                currentDays=currentDays-n;
                return;
            }
            var dd = data.dateStr;
            if(dd==getNowDateString()){
                dd='<img src="../../static/image/today.png">'+dd;
            }
            setElementInnerHTML("statDate",dd);
            setElementInnerHTML("totalCount",data.totalCount);
            var tc='';
            if(data.totalPoints>=0){
                tc='<font color="green">+'+data.totalPoints+'</font>';
            }else{
                tc='<font color="red">'+data.totalPoints+'</font>';
            }
            setElementInnerHTML("totalPoints",tc);
            setElementInnerHTML("currentPoints",data.currentPoints);
            loadUserRewardPoints(date);
        });
    }
    function loadUserRewardPoints(date) {
        if(date!=null){
            var formData = {
                startDate:date,
                endDate:date,
            }
            setPage(1);
            $('#search-form').loadJson(formData);
        }
        var url = '/userRewardPointRecord/getData';
        loadListData('search-form','dataContent','page',url,createRow,null);
    }
    function getDivId(id) {
        return 'UserRewardPointRecord'+id;
    }
    function createRow(rowData) {
        var html='';
        html+='<div id="'+getDivId(rowData.id)+'">';
        html+='<div class="weui-form-preview">';
        html+='    <a class="weui-cell  weui-cell_access weui-cell_example" href="javascript:showEdit('+rowData.id+');">\n';
        html+='        <div class="weui-cell__hd"><img src="../../static/image/points.png"></div>\n';
        html+='        <div class="weui-cell__bd">\n';
        var tc='';
        if(rowData.rewards>=0){
            tc='<font color="green">+'+rowData.rewards+'</font>';
        }else{
            tc='<font color="red">'+rowData.rewards+'</font>';
        }
        html+='<label class="weui-form-preview__label">奖励积分:'+tc+'</label>';
        html+='        </div>\n';
        html+='        <div class="weui-cell__ft">类型:'+rowData.rewardSourceName+'</div>\n';
        html+='    </a>\n';
        html+='    <div class="weui-form-preview__bd">\n';
        html+='        <div class="weui-form-preview__item">\n';
        html+='            <label class="weui-form-preview__label">创建时间</label>\n';
        html+='            <span class="weui-form-preview__value">'+rowData.createdTime+'</span>\n';
        html+='        </div>\n';
        html+='        <div class="weui-form-preview__item">\n';
        html+='            <label class="weui-form-preview__label">累计积分</label>\n';
        html+='            <span class="weui-form-preview__value">'+rowData.afterPoints+'</span>\n';
        html+='        </div>\n';
        html+='        <div class="weui-form-preview__item">\n';
        html+='            <label class="weui-form-preview__label">来源</label>\n';
        html+='            <span class="weui-form-preview__value mulanbay-dark-font">'+rowData.sourceName+'</span>\n';
        html+='        </div>\n';
        html+='        <div class="weui-form-preview__item">\n';
        html+='            <label class="weui-form-preview__label">备注</label>\n';
        html+='            <span class="weui-form-preview__value mulanbay-dark-font">'+rowData.remark+'</span>\n';
        html+='        </div>\n';
        html+='    </div>\n';
        html+='    <div class="weui-form-preview__ft">\n';
        html+='        <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:showRewardContent('+rowData.id+');">消息内容</a>\n';
        html+='    </div>\n';
        html+='</div>\n';
        html+='</div>\n';
        html+='<br>\n';
        return html;
    }
    function showRewardContent(id) {
        var url='/userRewardPointRecord/getMessageContent?id='+id;
        doAjax(null,url,'GET',false,function(data) {
            showInfoMsg(data);
        });
    }
</script>
</body>
</html>